# Copyright 2023 Ant Group Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package(default_visibility = ["//visibility:public"])

cc_library(
    name = "copy_to_proto_vistor",
    hdrs = ["copy_to_proto_vistor.h"],
    deps = [
        "@org_apache_arrow//:arrow",
    ],
)

cc_library(
    name = "logging",
    srcs = ["logging.cc"],
    hdrs = ["logging.h"],
    deps = [
        "@com_github_brpc_brpc//:butil",
        "@com_github_gabime_spdlog//:spdlog",
        "@yacl//yacl/base:exception",
    ],
)

cc_library(
    name = "prometheus_monitor",
    srcs = ["prometheus_monitor.cc"],
    hdrs = ["prometheus_monitor.h"],
    deps = [
        "@com_github_jupp0r_prometheus_cpp//core",
        "@yacl//yacl/base:exception",
    ],
)

cc_library(
    name = "psi_helper",
    srcs = ["psi_helper.cc"],
    hdrs = ["psi_helper.h"],
    deps = [
        ":stringify_visitor",
        "//engine/core:primitive_builder",
        "//engine/core:string_tensor_builder",
        "//engine/framework:exec",
        "@com_github_msgpack_msgpack//:msgpack",
        "@com_github_gabime_spdlog//:spdlog",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@psi//psi/ecdh:ecdh_oprf_psi",
        "@psi//psi/utils:batch_provider",
        "@psi//psi/utils:ec_point_store",
        "@psi//psi/utils:ub_psi_cache",
    ],
)

cc_library(
    name = "psi_detail_logger",
    srcs = ["psi_detail_logger.cc"],
    hdrs = ["psi_detail_logger.h"],
    deps = [
        ":logging",
        ":spu_io",
        "//engine/core:tensor",
        "@psi//psi/cryptor:ecc_cryptor",
        "@psi//psi/ecdh:ecdh_logger",
    ],
)

cc_library(
    name = "tensor_util",
    srcs = ["tensor_util.cc"],
    hdrs = ["tensor_util.h"],
    deps = [
        ":copy_to_proto_vistor",
        "//engine/core:arrow_helper",
        "//engine/core:tensor",
        "//engine/util:time_util",
        "@yacl//yacl/base:exception",
    ],
)

cc_test(
    name = "psi_helper_test",
    srcs = ["psi_helper_test.cc"],
    deps = [
        ":psi_helper",
        "//engine/core:primitive_builder",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "stringify_visitor",
    srcs = ["stringify_visitor.cc"],
    hdrs = ["stringify_visitor.h"],
    deps = [
        "//engine/core:arrow_helper",
        "//engine/core:tensor",
        "//engine/core:tensor_chunk",
    ],
)

cc_library(
    name = "spu_io",
    srcs = ["spu_io.cc"],
    hdrs = ["spu_io.h"],
    deps = [
        ":ndarray_to_arrow",
        "//engine/core:arrow_helper",
        "//engine/core:tensor",
        "//engine/core:type",
        "@org_apache_arrow//:arrow",
        "@spulib//libspu/core:xt_helper",
        "@spulib//libspu/device:io",
        "@spulib//libspu/kernel/hal:constants",
        "@spulib//libspu/kernel/hal:public_helper",
        "@spulib//libspu/kernel/hlo:casting",
    ],
)

cc_library(
    name = "ndarray_to_arrow",
    srcs = ["ndarray_to_arrow.cc"],
    hdrs = ["ndarray_to_arrow.h"],
    deps = [
        "//engine/core:arrow_helper",
        "//engine/core:type",
        "@org_apache_arrow//:arrow",
        "@spulib//libspu/core:ndarray_ref",
        "@spulib//libspu/core:xt_helper",
    ],
)

cc_library(
    name = "filepath_helper",
    srcs = ["filepath_helper.cc"],
    hdrs = ["filepath_helper.h"],
    deps = [
        "@com_google_absl//absl/strings",
        "@yacl//yacl/base:exception",
    ],
)

cc_library(
    name = "time_util",
    srcs = ["time_util.cc"],
    hdrs = ["time_util.h"],
    deps = [
        "//engine/core:primitive_builder",
        "//engine/core:tensor",
        "@org_apache_arrow//:arrow",
        "@yacl//yacl/base:exception",
    ],
)

cc_test(
    name = "filepath_helper_test",
    srcs = ["filepath_helper_test.cc"],
    linkopts = [
        "-lm",
    ],
    deps = [
        ":filepath_helper",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "table_util",
    srcs = ["table_util.cc"],
    hdrs = ["table_util.h"],
    deps = [
        "//engine/framework:exec",
        "@yacl//yacl/base:exception",
    ],
)

cc_library(
    name = "communicate_helper",
    hdrs = ["communicate_helper.h"],
    deps = [
        "//engine/util:spu_io",
        "@com_github_msgpack_msgpack//:msgpack",
    ],
)
